package com.example.demo.Controller;



import com.example.demo.Entity.User;
import com.example.demo.Repository.UserRepo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.DataAccessException;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;

import java.util.Map;
import java.util.Optional;

@Service
public class UserLoginServiceDemo {

    private final JdbcTemplate jdbcTemplate;
    private final UserRepo userRepo;

    @Autowired
    public UserLoginServiceDemo(JdbcTemplate jdbcTemplate,
                                UserRepo userRepo) {
        this.jdbcTemplate = jdbcTemplate;
        this.userRepo = userRepo;
    }


    public boolean registerUser(String username,String password){
        try {
            User user = new User();
            user.setUsername(username);
            user.setPassword(password);
            user.setRole("user");//默认是普通用户
            user.setStatus(1);
            userRepo.save(user);
            return true;
        } catch (DataAccessException e) {
            return false;
        }
    }
}
